package com.ctgu.expresshelper.controller;


import com.ctgu.expresshelper.entity.Address;
import com.ctgu.expresshelper.service.address.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private AddressService addressService;


    /**
     * 根据userID查询用户地址
     * @param userId
     * @return
     */
    @GetMapping("/{userId}")
    @ResponseBody
    public List<Address> getAllShopByUserId(@PathVariable int userId){
        return addressService.getAllShopByUserId(userId);
    }

    /**
     * 根据id 删除地址
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public int deleteAddress(@PathVariable int id){
        return addressService.deleteAddress(id);
    }


    /**
     * 修改地址
     * @param address
     */
    @PutMapping("/updateAddress")
    public void updateAddressById(@RequestBody Address address){
         addressService.updateAddressById(address);
    }

    /**
     * 添加地址
     * @param address
     */
    @PostMapping("/addAddress")
    public void addAddress(@RequestBody Address address){
        addressService.addAddress(address);
    }

}
